/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("suppliermodel",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.demo.IServices;

namespace VOL.demo.Controllers
{
    public partial class suppliermodelController
    {
        private readonly IsuppliermodelService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public suppliermodelController(
            IsuppliermodelService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 获取供货商下拉框数据
        /// </summary>
        /// <returns>供货商列表（ID和名称）</returns>
        [HttpGet("GetDropdownList")]
        public async Task<IActionResult> GetDropdownList()
        {
            try
            {
                var suppliers = await _service.GetSupplierOptionsAsync();
                return Json(new { success = true, data = suppliers, message = "查询成功" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = $"查询失败：{ex.Message}" });
            }
        }
    }
}
